#include <QApplication>
#include <QTextDocument>
#include <QTextStream>
#include <QFile>
#include <QPrinter>
#include <QDir>
#include <QCoreApplication>


int print(){
    QDir::setCurrent(QCoreApplication::applicationDirPath());

    QFile  htmlFile ("/home/hps/hps/Markdown-cpp/tests/TestData/huangpeishen/read.html");
    if (!htmlFile.open(QIODevice::ReadOnly | QIODevice::Text)){
        return -1;
    }

    QString htmlContent;
    QTextStream in(&htmlFile);
    htmlContent=in.readAll();

    QTextDocument *document = new QTextDocument();
    document->setHtml(htmlContent);

    QPrinter printer(QPrinter::HighResolution);
    printer.setPageSize(QPrinter::A4);
    printer.setOutputFormat(QPrinter::PdfFormat);

    printer.setOutputFileName("/home/hps/hps/Markdown-cpp/tests/TestData/huangpeishen/read.pdf");

    document->print(&printer);
    delete document;
    return 0;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);


    if(print() < 0) return -1;

    return a.exec();
}